/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2024-01-17
 * Time: 12:56
 */
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class OrderingInfo {//订单查看
    private Foods foods[];
    private int count;
    public OrderingInfo() {
        foods = new Foods[100];
        for(int i = 0;i < foods.length; i ++) {
            foods[i] = new Foods();
        }
    }

    public void show() {
        try (BufferedReader br = new BufferedReader(new FileReader("foodsInfo.txt"))) {//读取文本中的所有菜品
            String line;
            while ((line = br.readLine()) != null) {
                String[] parts = line.split("\t\t");
                foods[count].setFoodsName(parts[0]);
                foods[count].setFoodsPrice(Integer.parseInt(parts[1]));
                count++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void displayOfOrder() {//显示所有未完成订单
        int num = (int)(Math.random() * 890 + 100);
        for(int i = 0;i <= (int)(Math.random() * 10); i++) {
            System.out.println("-------------------------------");
            System.out.println("单号：" + num + i);
            newOrder();
            System.out.println("-------------------------------");
        }
    }

    public void newOrder() {//一份订单的信息
        int num = (int)(Math.random() * 5 + 1);
        System.out.println("菜名\t\t\t\t\t份数");
        for(int i = 0;i <= num; i++) {
            int j = (int)(Math.random() * (count - 1));
            int k = (int)(Math.random() * 3 + 1);
            String line = foods[j].getFoodsName() + "\t\t" + k + "份";
            line = line.format("%-10s\t\t%d份", foods[j].getFoodsName(), k);
            System.out.println(line);
        }
    }
}